import abc
from typing import Generic, TypeVar

from .dock import DockPlugin

AnyResumeArgs = TypeVar('AnyResumeArgs')
AnyPauseArgs = TypeVar('AnyPauseArgs')


class Resumable(Generic[AnyResumeArgs, AnyPauseArgs], abc.ABC):
    def on_resume(self, args: AnyResumeArgs):
        pass

    def on_pause(self, args: AnyPauseArgs):
        pass


class ResumableController(DockPlugin, Generic[AnyResumeArgs, AnyPauseArgs]):
    def resume(self, args: AnyResumeArgs):
        self._resume(args)

    def _resume(self, args: AnyResumeArgs):
        self.dock.scan_call_plugins(
            self.dock.iter_plugins(Resumable),
            lambda plugin: plugin.on_resume(args))

    def pause(self, args: AnyPauseArgs):
        self._pause(args)

    def _pause(self, args: AnyPauseArgs):
        self.dock.scan_call_plugins(
            self.dock.iter_plugins(Resumable),
            lambda plugin: plugin.on_pause(args))
